function res = BaselineAllocation(lambda,pr,w,pai)
% INPUT  : lamdba = tax parameter in HSV tax
%          pr     = parameters
%          w      = exp(alpha)
%          pai    = density
% OUTPUT : res    = residual of the resource constraint

temp = pr.sig+pr.tau+pr.gam*(1-pr.tau);

c = lambda^((1+pr.sig)/temp).*(1-pr.tau)^((1-pr.tau)/temp).*pr.Om^(-(1-pr.tau)/temp).*w.^((1-pr.tau)*(1+pr.sig)/temp);  
y = lambda^((1-pr.gam)/temp).*(1-pr.tau)^(1/temp)         .*pr.Om^(-1/temp)         .*w.^((1+pr.sig)/temp);

G = pr.g*sum(pai.*y); % Government expenditure 

res =  sum(pai.*y)-sum(pai.*c)-G;

save c c
save y y
save G G